package myky.com.doctorapp.ui

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import butterknife.ButterKnife
import butterknife.OnClick
import butterknife.Unbinder
import com.gyf.barlibrary.ImmersionBar
import com.m7.imkfsdk.KfStartHelper
import kotlinx.android.synthetic.main.public_common_title.*
import myky.com.doctorapp.R
import myky.com.doctorapp.base.CMApplication
import myky.com.doctorapp.utils.Constants
import myky.com.doctorapp.utils.ShareUtil
import myky.com.doctorapp.utils.SharedPre

/**
 * Description: 帮助主页面
 * @author xiangyao
 * Created by 2019/3/15 5:50 PM
 */
class HelpActivity : AppCompatActivity() {

    lateinit var unbinder: Unbinder

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_help)
        unbinder = ButterKnife.bind(this)
        ImmersionBar.with(this).barColorInt(resources.getColor(R.color.colorPrimary)).titleBar(R.id.commonTitleLayout).navigationBarEnable(false).init()

        initView()


    }

    private fun initView() {

        conmonTitleTextView.text="问题与帮助"
    }


    @OnClick(R.id.backLayout,R.id.aboutLogin, R.id.abloutMessageLayout,R.id.aboutHealthFile,
            R.id.aboutDiseasePrpfile,R.id.aboutConsultLayout,R.id.aboutLongConsultLayout,
            R.id.aboutYuyue,R.id.make_online_consult)
    fun onClick(view: View) {
        when (view.id) {
            R.id.aboutLogin -> {

                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,0)

                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)


                startActivity(intent)

            }
            R.id.abloutMessageLayout -> {

                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,1)

                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)

                startActivity(intent)
            }
            R.id.aboutHealthFile -> {
                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,2)

                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)


                startActivity(intent)
            }
            R.id.aboutDiseasePrpfile -> {
                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,3)


                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)


                startActivity(intent)
            }
            R.id.aboutConsultLayout -> {
                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,4)

                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)


                startActivity(intent)
            }
            R.id.aboutLongConsultLayout -> {
                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,5)

                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)

                startActivity(intent)
            }
            R.id.aboutYuyue -> {
                var bundle=Bundle()
                bundle.putInt(Constants.HELPTEXTINDEX,6)


                var intent=Intent()
                intent.setClass(this,HelpTextActivity::class.java)
                intent.putExtras(bundle)

                startActivity(intent)
            }
            R.id.make_online_consult -> {


                val user_bean = SharedPre.getUser_bean(this)
                val username: String
                val mobile: String
                if (user_bean != null && user_bean.userName != null && !TextUtils.isEmpty(user_bean.userName)) {
                    username = SharedPre.getUser_bean(this).userName
                } else {
                    username = "访客"
                }
                if (user_bean != null && user_bean.phone != null && !TextUtils.isEmpty(user_bean.phone)) {
                    mobile = SharedPre.getUser_bean(this).phone
                } else {
                    mobile = ""
                }

                val nickName: String
                val userId: String
                if (CMApplication.getInstance().isLoginOk) {
                    userId = ShareUtil.getUserId(Constants.USERID)
                    nickName = username + "_" + mobile
                } else {
                    userId = ((Math.random() * 9 + 1) * 1000).toInt().toString()
                    nickName = "访客"
                }


                val helper = KfStartHelper(this)
                helper.initSdkChat("ba6bf790-4f86-11e8-a899-6d1f9ec76555", nickName, userId)

            }
            R.id.backLayout->{
                finish()
            }

        }

    }


    override fun onDestroy() {
        super.onDestroy()

        unbinder.unbind()
    }
}